Added 'times' option to saroute, to synthesize tracks
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 14 Mar 2006 15:09:54 +0000 (15:09 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 14 Mar 2006 15:09:54 +0000 (15:09 +0000)
gpsbabel/readme.xml
gpsbabel/saroute.c

index 488e874964554e02caf9ed6b8188eb741ac1f794..10b7c10632f2ef3a6fde5090fb0bc109f5e49dd4 100644 (file)
@@ -212,7 +212,7 @@ mouse pointer hover over it for a few seconds and the name will be
 displayed.</para>
       <para>The "color" option allows you to specify the color for
 line or mapnote data.  It accepts color names of the form "#FF0000" (red) or any
-of the 16 common color names from the Cascading Style Sheets
+of the color names from the Cascading Style Sheets (CSS)
 specification.i</para>
       <para>The "wpt_type" option specifies how to represent point data
 in the draw file.  Valid waypoint types are "marker", "text", "mapnote",
@@ -1403,6 +1403,10 @@ named 'control points' containing just the control points in order.
 Note that if your goal is to create an arc or other CSV file, you
 should use 'none' (or not use this option, which is the same
 thing.)</para>
+      <para>The 'times' option causes GPSBabel to read the route as if
+it were a track, synthesizing times starting from the current time, using
+the estimated travel times specified in your route file (you can change your
+travel speeds in the DeLorme product you used to create the route file.)</para>
       <para> All options only apply to route files from newer (anr)
 versions of DeLorme software; older versions didn't store the turn
 information with the route.
index 239b08a34f4f7d6a27e53da2528171b5f83402f6..a2f4c93e2b3628ed75fbafdbd4fc343a3953152b 100644 (file)
@@ -25,6 +25,7 @@
 
 #define MYNAME "saroute"
 #include "defs.h"
+#include "grtcirc.h"
 
 FILE *infile;
 
@@ -32,6 +33,7 @@ char *turns_important = NULL;
 char *turns_only = NULL;
 char *controls = NULL;
 char *split = NULL;
+char *times = NULL;
 
 int control = 0;
 
@@ -46,6 +48,8 @@ arglist_t saroute_args[] = {
                        NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
        {"controls", &controls, "Read control points as waypoint/route/none",
                "none", ARGTYPE_STRING, ARG_NOMINMAX },
+       {"times", &times, "Synthesize track times",
+               NULL, ARGTYPE_BOOL, ARG_NOMINMAX },
        ARG_TERMINATOR
 };
 
@@ -131,6 +135,13 @@ my_read(void)
        route_head *old_track_head = NULL;
        waypoint *wpt_tmp;
        char *routename = NULL;
+       double seglen = 0.0;
+       long  starttime = 0;
+       long  transittime = 0;
+       double totaldist = 0.0;
+       double oldlat = 0;
+       double oldlon = 0;
+       int first = 0;
 
        ReadShort(infile);              /* magic */
        version = ReadShort(infile);
@@ -171,7 +182,12 @@ my_read(void)
         */
        if ( version < 6 || (control == 1)) {
                track_head = route_head_alloc();
-               route_add_head(track_head);
+               if ( times ) {
+                       track_add_head(track_head);
+               }
+               else {                  
+                       route_add_head(track_head);
+               }
                if ( control ) {
                    track_head->rte_name = xstrdup("control points");
                }
@@ -270,7 +286,12 @@ my_read(void)
                count = ReadLong(infile);
                if ( count ) {
                        track_head = route_head_alloc();
-                       route_add_head(track_head);
+                       if ( times ) {
+                               track_add_head(track_head);
+                       }
+                       else {
+                               route_add_head(track_head);
+                       }
                        if ( routename && !split ) {
                            track_head->rte_name = xstrdup( routename );
                        }
@@ -285,7 +306,12 @@ my_read(void)
                            if ( track_head->rte_waypt_ct ) {
                                old_track_head = track_head;
                                track_head = route_head_alloc();
-                               route_add_head( track_head );
+                               if ( times ) {
+                                       track_add_head( track_head );
+                               }
+                               else {
+                                       route_add_head( track_head );
+                               }
                            } // end if
                            if ( !track_head->rte_name ) {
                                track_head->rte_name = 
@@ -295,6 +321,16 @@ my_read(void)
                                track_head->rte_name[stringlen] = '\0';
                            } 
                        }
+                       
+                       if ( times ) {
+                               le_read64( &seglen, 
+                                          record + 2 + stringlen + 0x08 );
+                               starttime = le_read32((unsigned long *)
+                                       (record + 2 + stringlen + 0x30 ));
+                               transittime = le_read32((unsigned long *)
+                                       (record + 2 + stringlen + 0x10 ));
+                               seglen /= 5280*12*2.54/100000; /* to miles */
+                       }
                                
                        coordcount = le_read16((unsigned short *)
                                        (record + 2 + stringlen + 0x3c));
@@ -303,6 +339,9 @@ my_read(void)
                        if (count) {
                                coordcount--;
                        }
+                       
+                       first = 1;
+                       
                        while (coordcount) {
                                double lat;
                                double lon;
@@ -330,6 +369,28 @@ my_read(void)
                                    sprintf( wpt_tmp->shortname, "\\%5.5x", 
                                                serial++ );
                                }
+                               if ( times ) {
+                                       if ( !first ) {
+                                          double dist = tomiles(gcdist( 
+                                               lat*M_PI/180, -lon*M_PI/180, 
+                                               oldlat*M_PI/180, 
+                                               -oldlon*M_PI/180 ));    
+                                          totaldist += dist;
+                                          if ( totaldist > seglen ) {
+                                                  totaldist = seglen;
+                                          }
+                                          wpt_tmp->creation_time = 
+                                              gpsbabel_time+starttime+
+                                              transittime * totaldist/seglen;
+                                       }
+                                       else {
+                                          wpt_tmp->creation_time = 
+                                              gpsbabel_time+starttime;
+                                          totaldist = 0;
+                                       }
+                                       oldlat = lat;
+                                       oldlon = lon;
+                               }
                                if ( turns_important && stringlen ) 
                                        wpt_tmp->route_priority=1;
                                if ( !turns_only || stringlen ) {
@@ -340,7 +401,6 @@ my_read(void)
                                                old_track_head = NULL;
                                        }
                                }
-                               
        
                                latlon++;
                                coordcount--;
@@ -349,6 +409,7 @@ my_read(void)
                                if ( coordcount == 1 && count == 0 ) {
                                        stringlen = 1;
                                }
+                               first = 0;
                        }
                        if ( version > 10 ) {
                                Skip(infile,2*sizeof(gbuint32));